package ru.usu.gv.view;

import ru.usu.gv.core.GraphEngine;
import ru.usu.gv.gui.actions.ActionBase;
import ru.usu.gv.gui.actions.AddEdgeAction;
import ru.usu.gv.uicomponents.UIElementBase;
import ru.usu.gv.uicomponents.UIVertex;

import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;

/**
 @author Sergey Pupyrev 
 11.01.2007
 */

public class AddEdgePickingClient extends PickingClientBase
{
    public void callback(MouseEvent e, UIElementBase element)
    {
        List<UIElementBase> pickedList = GraphEngine.getInstance().getPickListener().getPickedList();
        List<UIVertex> vertexList = new ArrayList<UIVertex>();
        for (UIElementBase item : pickedList)
            if (item instanceof UIVertex)
                vertexList.add((UIVertex)item);

        if (vertexList.size() == 2)
        {
            ActionBase action = new AddEdgeAction(vertexList.get(0), vertexList.get(1));
            action.execute();
            GraphEngine.getInstance().getPickListener().setDefaultState();
            //TODO: unregister and redraw
        }
    }

}
